<?php

class BlogController extends Site_Controller_Action
{
    
    private $_table     = 'BLOG';
    private $_pk        = 'BLO_ID';
    private $_order_col = 'BLO_DAT';
    private $_order     = 'DESC';
    private $_sta_col   = 'BLO_STA';
    private $obj        = '';
    private $form       = '';
    private $_file_col  = 'BLO_FILE'; 
    public  $dir        = 'public/upload/blog/';
    
    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        Zend_Loader::loadClass('datetools','library');
        
        $query = 'SELECT SQL_CACHE * FROM PAGINA_SITE WHERE PGS_LNK like "%blog%"';
        $result = $this->db->fetchRow($query);
        $this->view->paginasite = $result;
        
        $where = 'BLO_STA = 1';
        
        $id = $this->_getParam('id', '');
        if($id != '') $where .= ' AND BLO_ID = '. $id;
        
        $tag = $this->_getParam('tag', '');
        if($tag != '') $where .= ' AND BLO_TAG LIKE "'. $tag.'"';
        
        $query = 'SELECT SQL_CACHE * FROM '.$this->_table.' WHERE '.$where.' ORDER BY '.$this->_order_col.' '.$this->_order;
        $result = $this->db->fetchAll($query);
        $this->view->result = $this->paginacao($result,5);
        
        $query = 'SELECT SQL_CACHE BLO_TAG FROM '.$this->_table.' WHERE BLO_STA = 1 GROUP BY BLO_TAG';
        $result = $this->db->fetchAll($query);
        $tags = '';
        foreach($result as $row) {
             $tags .= '<a href="'.$this->_urlbase.'/'.$this->_controller.'/index/tag/'.$row['BLO_TAG'].'">'.$row['BLO_TAG'].'</a>, ';
        }
        $tags = substr($tags,0,-2);
        $this->view->tags = $tags;
    }
}

